import request from "@/utils/request";
import { store } from "@/utils/global";
import { treeDataInit } from "@/utils/coverage/coverage";
import { getAllDrawData } from "@/api/draw";
/**
 * 获取地图图层树
 * @returns
 */
export const getCoverage = async () => {
    return await request.get(`/sxnf_team/baseFolder/list?id=${store.baseId}`).then((res) => {
        let data = res.data;
        if (!store.treeDefaultKey) {
            store.treeDefaultKey = data[0].id;
            setTimeout(() => {
                // console.log(store.tree.getNode(store.treeDefaultKey));
                store.tree.getNode(store.treeDefaultKey).expanded = true;
            }, 300);
        }
        store.treeData = data;
        // 初始化图层数据
        treeDataInit(data);
        // 获取所有标绘数据
        getAllDrawData();
        return res;
    });
};
/**
 * 修改文件夹名称
 */

export const updateFloaderName = async (data = {}) => {
    return await request.post("/sxnf_team/baseFolder/update", data).then((res) => {
        return res;
    });
};

/**
 * 修改文件锁定状态
 */

export const updateFloaderLock = async (data = {}) => {
    return await request.post("/sxnf_team/baseFolder/modifyTheLockState", data).then((res) => {
        return res;
    });
};

/**
 * 添加文件夹
 */

export const addFloader = async (data = {}) => {
    return await request.post("/sxnf_team/baseFolder/add", data).then((res) => {
        return res;
    });
};

/**
 * 删除文件夹
 */

export const deleteFloader = async (data = {}) => {
    return await request.post("/sxnf_team/baseFolder/deleteById", data).then((res) => {
        return res;
    });
};

/**
 * 删除文件夹所有数据
 */

export const deleteFloaderAllData = async (data = {}) => {
    return await request.post("/sxnf_team/draw/clearFolderContent", data).then((res) => {
        return res;
    });
};
/**
 * 设置标绘显示状态
 */

export const updateFloaderShow = async (data = {}) => {
    return await request.post("/sxnf_team/baseFolder/modifyThePlotDisplay ", data).then((res) => {
        return res;
    });
};
/**
 * 标绘上移
 */
export const updateFloaderUp = async (data = {}) => {
    return await request.post("/sxnf_team/baseFolder/moveItemUpByDraw", data).then((res) => {
        return res;
    });
};
/**
 * 标绘下移
 */
export const updateFloaderDown = async (data = {}) => {
    return await request.post("/sxnf_team/baseFolder/moveItemDownByDraw", data).then((res) => {
        return res;
    });
};
/**
 * 文件夹上移
 */
export const updateFloaderUpFolder = async (data = {}) => {
    return await request.post("/sxnf_team/baseFolder/moveItemUpByBaseFoler", data).then((res) => {
        return res;
    });
};
/**
 * 文件夹下移
 */
export const updateFloaderDownFolder = async (data = {}) => {
    return await request.post("/sxnf_team/baseFolder/moveItemDownByBaseFoler", data).then((res) => {
        return res;
    });
};
/**
 * 标绘数据锁定和解锁操作
 */
export const updateFloaderLockDraw = async (data = {}) => {
    return await request.post("/sxnf_team/baseFolder/modifyTheLockStateByDraw", data).then((res) => {
        return res;
    });
};
/**
 * 文件夹粘贴
 */
export const copyFolder = async (data = {}) => {
    return await request.post("/sxnf_team/baseFolder/copyFolder", data).then((res) => {
        return res;
    });
};
